<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="modal fade" id="modal-qttHistory">
    <div class="modal-dialog" style="width:90%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">查看历史报价</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <form id="qttHistoryForm" class="form-horizontal">
                        <input type="hidden" name="quoteId">
                    </form>
                    <table id="bootstrap-table1"></table>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" type="button" data-dismiss="modal" aria-label="Close">关闭</button>
            </div>
        </div>
    </div>
</div>
<style>
    .table-border tbody tr td{
        border-top: 1px solid black;
    }
</style>
<section class="content-header">
    <h1>报价单查询</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="proCode" class="form-control" placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="proName" class="form-control" placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>报价版本类型</label>
                                    <select name="quoteAvaStatus" class="form-control" onchange="changeQuoteStatus(this.value)">
                                        <option value="" selected="selected">全部</option>
                                        <option value=1>临时报价</option>
                                        <option value=2>最终报价</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>报价执行状态</label>
                                    <select name="quoteStatus" id="quoteStatus" class="form-control">
                                        <option value="">全部</option>
                                        <option value=1>待提交</option>
                                        <option value=2>待审核</option>
                                        <option value=4  selected="selected">审核通过</option>
                                        <option value=5>审核驳回</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>创建人</label>
                                    <input type="text" name="createName" class="form-control" placeholder="请输入创建人姓名">
                                </div>
                                <div class="form-group">
                                    <label>创建日期</label>
                                    <input type="text" class="form-control datepicker" name="quoteStartDate"
                                           placeholder="请选择">
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" name="quoteEndDate"
                                           placeholder="请选择">
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">&emsp;搜索&emsp;</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" class="table-border"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    // /**
    //  *确认报价
    //  */
    // function compQuotation(quoteId) {
    //     js.modal.confirm("确认此报价吗？", function () {
    //         js.post({
    //             url: ctx + "quoteManage/quotationQuery/complete",
    //             data: {
    //                 quoteId: quoteId
    //             },
    //             success: function (result) {
    //                 if (result.type === web_status.SUCCESS) {
    //                     js.modal.success(result.msg);
    //                     js.table.refresh(table);
    //                 } else {
    //                     js.modal.warning(result.msg);
    //                 }
    //                 js.modal.closeLoading();
    //             }
    //         })
    //     })
    // }
    //
    // /**
    //  * 报价存为历史版本
    //  */
    // function reQtt(quoteId, quoteProcessStatus) {
    //     js.modal.confirm("重新报价后，此报价单将返回至报价创建人待提交状态，确认重新此报价吗？", function () {
    //         js.post({
    //             url: ctx + "quoteManage/quotationQuery/reQtt",
    //             data: {
    //                 quoteId: quoteId,
    //                 quoteProcessStatus: quoteProcessStatus
    //             },
    //             success: function (result) {
    //                 if (result.type === web_status.SUCCESS) {
    //                     js.modal.success(result.msg);
    //                     js.table.refresh(table);
    //                 } else {
    //                     js.modal.warning(result.msg);
    //                 }
    //                 js.modal.closeLoading();
    //             }
    //         })
    //     })
    // }

    //报价任务状态更改时，更改报价执行状态
    function changeQuoteStatus(quoteValue){
        if(quoteValue == 2){
            $("#quoteStatus").val('4');
            $("#quoteStatus").prop("disabled", true);

        }else {
            $("#quoteStatus").val('');
            $("#quoteStatus").prop("disabled", false);
        }
    }

    function viewHistoryQtt(quoteId){
        $("#qttHistoryForm input[name ='quoteId']").val(quoteId);

        /**
         * 加载列表
         */
        table1 = js.table.init({
            id:"bootstrap-table1",
            queryForm: "qttHistoryForm",
            url: ctx + "quoteManage/qttHistory/list",
            showColumns: true,
            showExport: true,
            columns: [
                {
                    title: '序号', field: 'id', width: '60',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: '项目编号', field: 'proCode', width: '100',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }
                },
                {title: '项目名称', field: 'proNames', width: '300',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }
                },
                {title: '物料名称', field: 'proName', width: '300',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }

                },
                // {title: '任务组', field: 'groupName', width: '200',
                //     formatter: function (value, row, index) {
                //         if (value != null) {
                //             return value.split(',').join('<br>');
                //         }
                //     }
                // },
                {title: '报价单版本号', field: 'quoteRevNo', width: '100px'},
                {title: '买方名称', field: 'consumerName', width: '120px'},
                {title: '创建人', field: 'supplierAttn', width: '100px'},
                {title: '创建日期', field: 'quoteGentDate', width: '120px'},
                {
                    title: '操作', field: 'operation', width: '140px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        //         if (hasP("halinv:haladjlist:edit")) {
                        actions.push('<a class="btn btn-info btn-xs" href="' + ctx + 'quoteManage/viewQuotation/quoteId/' + row.qttPrtId + '">&nbsp;&nbsp;查&nbsp;&nbsp;&nbsp;&nbsp;看&nbsp;&nbsp;</a> ');
                        return actions.join('');
                    }
                }
            ]
        });
        js.table.search(table1);
        js.modal.open("modal-qttHistory");
    }

    var table;
    var table1;
    $(function () {
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "quoteManage/quotationSearch/list",
            showColumns: true,
            showExport: true,
            onLoadSuccess: function (data) {
                var dataSource = $('#bootstrap-table').bootstrapTable('getData', true);
            },
            columns: [
                {
                    title: '序号', field: 'id', width: '80',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: '项目编号', field: 'proCode', width: '180',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }
                },
                {title: '项目名称', field: 'proName', width: '300',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }
                },
                {
                    title: '物料名称', field: 'proNames', width: '300',
                    formatter: function (value, row, index, field) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }
                },


                {title: '买方名称', field: 'consumerName', width: '180px'},
                // {title: '任务组', field: 'groupName', width: '150',
                //     formatter: function (value, row, index) {
                //         if (value != null) {
                //             return value.split(',').join('<br>');
                //         }
                //     }
                // },
                {
                    title: '报价版本</br>类型', field: 'quoteAvaStatus', width: '120',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge ' + ["label-warning"] + '">' + '临时报价' + '</span> ';
                        } else if (value === 2) {
                            return '<span class="badge ' + ["label-success"] + '">' + '最终报价' + '</span> ';
                        }
                    }
                },
                {
                    title: '报价执<br>行状态', field: 'quoteStatus', width: '120',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge ' + ["label-default"] + '">' + '待提交' + '</span> ';
                        } else if (value === 2 || value === 3) {
                            return '<span class="badge ' + ["label-warning"] + '">' + '待审核' + '</span> ';
                        } else if (value === 4) {
                            return '<span class="badge ' + ["label-success"] + '">' + '审核通过' + '</span> ';
                        }else if (value === 5) {
                            return '<span class="badge ' + ["label-danger"] + '">' + '审核驳回' + '</span> ';
                        }
                    }
                },
                // {title: '报价单编号', field: 'quoteNo', width: '160px'},

                {title: '创建人', field: 'createName', width: '100px'},
                {title: '创建日期', field: 'quoteGentDate', width: '140px'},
                {
                    title: '操作', field: 'operation', width: '100px',
                    formatter: function (value, row, index) {
                        var actions = [];

                        // if ( row.quoteStatus == 4 && row.quoteProcessStatus == 2) {

                            //     // if (hasP("quo:comList:complete")) {
                            //         actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="compQuotation(' + row.quoteId + ')">&nbsp;&nbsp;完&nbsp;&nbsp;&nbsp;&nbsp;结&nbsp;&nbsp;</a>');
                            //     // }
                            //     // if (hasP("quo:comList:confirm")) {
                            //         actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="reQtt(' + row.quoteId + ',' + row.quoteProcessStatus + ')">重新报价</a>');
                            //     // }
                            // }

                        // }else if(row.quoteStatus == 4 && row.quoteProcessStatus == 3){
                        //     if([[${session.user.account}]] == [[${sysUserModel.account}]]){
                        //         // if (hasP("quo:comList:confirm")) {
                        //             actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="reQtt(' + row.quoteId + ',' + row.quoteProcessStatus + ')"> 重新报价</a>');
                        //         // }
                        //     }
                        // }
                        if(hasP("quo:await:view")){
                            actions.push('<a class="btn btn-info btn-xs" href="' + ctx + 'quoteManage/viewQuotation/quoteId/' + row.quoteId + '">查看</a> ');
                            // if(row.qttHisQty > 0){
                            //     actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="viewHistoryQtt(' + row.quoteId + ')">查看历史</a> ');
                            // }
                            }
                        return actions.join('');
                    }
                }
            ]
        });

        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

    });
</script>
</body>
</html>